package cglib;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @Author:zimmor
 * @Date: 2021/3/25 13:03
 * @Description 通过匿名内部类来使用CGlib
 * @version: 1.0.0
 */

public class DynamicProxyDemo {
    public static void main(String[] args) {
        Buyer proxy = (Buyer) Enhancer.create(Buyer.class, new MethodInterceptor() {
            public Object intercept(Object target, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
                System.out.println("代理开始工作");
                return methodProxy.invokeSuper(target,args);
            }
        });
        System.out.println("proxy.buybuybuy() = " + proxy.buybuybuy());

    }
}
